
package de.justphil.tcg.tcgandroidclient.gui;

import de.justphil.tcg.tcgandroidclient.R;
import de.justphil.tcg.tcgandroidclient.gui.gameboard.GameBoardAct;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.Window;

public class SplashAct extends Activity {
	
	private boolean enabled = true;
	private final static int SPLASH_TIME = 5000;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
	
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.splash);
		// thread for displaying the SplashScreen
		Thread splashTread = new Thread() {
			
			@Override
			public void run() {
			
				try {
					int waited = 0;
					while (enabled && (waited < SPLASH_TIME)) {
						sleep(100);
						if (enabled) {
							waited += 100;
						}
					}
				}
				catch (InterruptedException e) {
					// do nothing
				}
				finally {
					finish();
					startActivity(new Intent(SplashAct.this, LoginAct.class));
				}
			}
		};
		splashTread.start();
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
	
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			enabled = false;
		}
		return true;
	}
}
